package com.fr.chart.core.glyph;

import com.fr.base.core.IteratorChain;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.LineGlyph;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class RangePlotGlyph extends PlotGlyph
{
  private static final long serialVersionUID = -3079867047500181470L;
  public static final String XML_TAG = "RangePlotGlyph";
  public static final double RectHeight = 50.0D;
  private LineGlyph middleLineGlyph;
  private RangeAxisGlyph rangeAxisGlyph = new RangeAxisGlyph();
  private double seriesWidth = 2.0D;
  private List rangeAxisGlyphList = new ArrayList();

  public void layoutAxisGlyph()
  {
    this.rangeAxisGlyphList.clear();
    int i = getCategoryCount();
    for (int j = 0; j < i; ++j)
    {
      double d1 = getBounds().getHeight();
      double d2 = getBounds().getWidth();
      double d3 = (d1 / i * 2 > 50.0D) ? 50.0D : d1 / i * 2;
      double d4 = (j + 1) * d1 / (1 + i) - d3 / 2.0D;
      Rectangle2D.Double localDouble = new Rectangle2D.Double(0.0D, d4, d2, d3);
      RangeAxisGlyph localRangeAxisGlyph = new RangeAxisGlyph();
      try
      {
        localRangeAxisGlyph = (RangeAxisGlyph)this.rangeAxisGlyph.clone();
      }
      catch (CloneNotSupportedException localCloneNotSupportedException)
      {
        localCloneNotSupportedException.printStackTrace();
      }
      localRangeAxisGlyph.init(localDouble, d1);
      localRangeAxisGlyph.calculateAxisLengthUnit();
      this.rangeAxisGlyphList.add(localRangeAxisGlyph);
    }
  }

  public void layoutDataSeriesGlyph()
  {
    for (int i = 0; i < getCategoryCount(); ++i)
      for (int j = 0; j < getSeriesSize(); ++j)
      {
        DataSeries localDataSeries = getSeries(j);
        DataPoint localDataPoint = localDataSeries.getDataPoint(i);
        if (localDataPoint.isValueIsNull())
          break label173:
        RangeAxisGlyph localRangeAxisGlyph = (RangeAxisGlyph)this.rangeAxisGlyphList.get(i);
        Point2D localPoint2D = localRangeAxisGlyph.getPoint2D(localDataPoint.getValue());
        double d1 = localRangeAxisGlyph.getBounds().getHeight();
        double d2 = localRangeAxisGlyph.getBounds().getY();
        Rectangle2D.Double localDouble = new Rectangle2D.Double(localPoint2D.getX() - getSeriesWidth() / 2.0D, d2 + localPoint2D.getY() - d1 / 2.0D, getSeriesWidth(), d1);
        ShapeGlyph localShapeGlyph = new ShapeGlyph(localDouble);
        localShapeGlyph.getInfo().dealCondition(getSeriesCollection(), j);
        localDataPoint.setDrawImpl(localShapeGlyph);
        dealDataPointLabelBounds(localDataPoint, j);
      }
    label173:
  }

  public Iterator selectableChildren()
  {
    ArrayList localArrayList = new ArrayList();
    if (this.middleLineGlyph != null)
      localArrayList.add(this.middleLineGlyph);
    if ((this.rangeAxisGlyphList != null) && (this.rangeAxisGlyphList.size() > 0))
      localArrayList.addAll(this.rangeAxisGlyphList);
    return new IteratorChain(new Iterator[] { super.selectableChildren(), localArrayList.iterator() });
  }

  public void draw(Graphics paramGraphics)
  {
    int i;
    drawInfo(paramGraphics);
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    if ((this.rangeAxisGlyphList != null) && (this.rangeAxisGlyphList.size() > 0))
      for (i = 0; i < this.rangeAxisGlyphList.size(); ++i)
        ((RangeAxisGlyph)this.rangeAxisGlyphList.get(i)).draw(localGraphics2D);
    localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
    super.draw(localGraphics2D);
  }

  public void setRangeAxisGlyph(RangeAxisGlyph paramRangeAxisGlyph)
  {
    this.rangeAxisGlyph = paramRangeAxisGlyph;
  }

  public RangeAxisGlyph getRangeAxisGlyph()
  {
    return this.rangeAxisGlyph;
  }

  public void setMiddleLineGlyph(LineGlyph paramLineGlyph)
  {
    this.middleLineGlyph = paramLineGlyph;
  }

  public LineGlyph getMiddleLineGlyph()
  {
    return this.middleLineGlyph;
  }

  public void setSeriesWidth(double paramDouble)
  {
    this.seriesWidth = paramDouble;
  }

  public double getSeriesWidth()
  {
    return this.seriesWidth;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("RangePlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("seriesWidth", getSeriesWidth()).end();
    if (this.rangeAxisGlyph != null)
      this.rangeAxisGlyph.writeXML(paramXMLPrintWriter);
    if (this.middleLineGlyph != null)
      this.middleLineGlyph.writeXML(paramXMLPrintWriter);
    if ((this.rangeAxisGlyphList != null) && (this.rangeAxisGlyphList.size() > 0))
    {
      paramXMLPrintWriter.startTAG("RangeList");
      for (int i = 0; i < this.rangeAxisGlyphList.size(); ++i)
        ReportXMLUtils.writeXMLable(paramXMLPrintWriter, (RangeAxisGlyph)this.rangeAxisGlyphList.get(i), "AxisGlyphList");
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("seriesWidth")) != null)
          setSeriesWidth(Double.valueOf(str2).doubleValue());
      }
      else if (str1.equals("RangeAxisGlyph"))
      {
        this.rangeAxisGlyph = ((RangeAxisGlyph)paramXMLableReader.readXMLObject(new RangeAxisGlyph()));
      }
      else if (str1.equals("LineGlyph"))
      {
        this.middleLineGlyph = ((LineGlyph)paramXMLableReader.readXMLObject(new LineGlyph()));
      }
      else if (str1.equals("RangeList"))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final RangePlotGlyph this$0;

          public void readXML()
          {
            if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("AxisGlyphList")))
            {
              RangeAxisGlyph localRangeAxisGlyph = (RangeAxisGlyph)ReportXMLUtils.readXMLable(paramXMLableReader);
              RangePlotGlyph.access$000(this.this$0).add(localRangeAxisGlyph);
            }
          }
        });
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof RangePlotGlyph))
      return false;
    RangePlotGlyph localRangePlotGlyph = (RangePlotGlyph)paramObject;
    if (!(super.equals(localRangePlotGlyph)))
      return false;
    if (localRangePlotGlyph.getSeriesWidth() != getSeriesWidth())
      return false;
    if (!(Equals.equals(localRangePlotGlyph.rangeAxisGlyph, this.rangeAxisGlyph)))
      return false;
    return (Equals.equals(localRangePlotGlyph.middleLineGlyph, this.middleLineGlyph));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    RangePlotGlyph localRangePlotGlyph = (RangePlotGlyph)super.clone();
    if (this.rangeAxisGlyph != null)
      localRangePlotGlyph.rangeAxisGlyph = ((RangeAxisGlyph)this.rangeAxisGlyph.clone());
    if (this.middleLineGlyph != null)
      localRangePlotGlyph.middleLineGlyph = ((LineGlyph)this.middleLineGlyph.clone());
    return localRangePlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if (this.rangeAxisGlyph != null)
      localJSONObject.put("rangeAxisGlyph", this.rangeAxisGlyph.toJSONObject());
    localJSONObject.put("middleLineGlyph", this.middleLineGlyph.toJSONObject());
    localJSONObject.put("seriesWidth", getSeriesWidth());
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "RangePlotGlyph";
  }

  static List access$000(RangePlotGlyph paramRangePlotGlyph)
  {
    return paramRangePlotGlyph.rangeAxisGlyphList;
  }
}